import router from '@system.router';
import prompt from '@system.prompt';
import http from '@ohos.net.http';

export default {
    data: {},
    clickBack() {
        router.back();
    },
    clickLogin() {
        prompt.showToast({
            message: this.input_uid + this.input_upwd
        })
    },
    submit(e) {
        const username = e.value.username;
        const password = e.value.password;
        let httpRequest = http.createHttp();
        httpRequest.request("http://8.140.58.204:8899",
            {
                method: 'POST',
                header: {
                    'Content-Type': 'text/plain'
                },
                extraData: {
                    "id": e.value.username,
                    "pwd": e.value.password
                },
            },
            (err, data) => {
                if (!err) {
                    console.log("收到服务器响应");
                    console.log('服务器响应数据:' + data.result);
                    if (data.responseCode == '200') {
                        prompt.showToast({
                            message: '用户:' + data.result + '欢迎登陆!'
                        });
                        setTimeout(this.clickBack, 2000);
                    }
                }
                else {
                    console.log("超时未响应");
                    prompt.showToast({
                        message: '服务器响应超时...'
                    })
                }
            });
    }
}
